package com.wz.utils.transaction.jdbctemplate.service.impl;

import com.wz.utils.transaction.jdbctemplate.pojo.User;
import com.wz.utils.transaction.jdbctemplate.service.UserService;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.Types;

/**
 * @Author : Wang Zhen.
 * @Date : Created in 19:44 2022/12/20
 * @Description :
 * @Modified By   :
 * @Version :
 */
public class UserServiceImpl implements UserService {
    private JdbcTemplate jdbcTemplate;

    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Override
    public void save(User user) {
        jdbcTemplate.update("insert into user(name, age, sex) value(?, ?, ?)",
                new Object[]{user.getName(), user.getAge(), user.getSex()},
                new int[]{Types.VARCHAR, Types.INTEGER, Types.VARCHAR});
        throw new RuntimeException("模拟运行时异常");
    }

}
